import dt from '@dt/dt'
import nameOpt from '@/biz/option/name.js'
import rolesOpt from '@/biz/option/roles.js'
import Opt from '@/components/dt/info/Opt.js'

let _this = null

function validateList() {
  let select = [
  {
    value: '全部',
    key: '',
  },
  {
    value: '启用',
    key: '1',
  },
  {
    value: '禁用',
    key: '2',
  }]
  return select
}

function userStatus() {
  let obj = {
    value: '全部',
    key: '',
  }
  let arr = [obj, ...dt.dictInfo().userStatus]
  return arr
}

class Column extends Opt {
  constructor(vm) {
    super()
    _this = vm
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {

    this.all = [
    {
      type: 'checkbox',
      width: 60,
      align: 'center',
    }, {
      title: '',
      field: 'ownerText',
      minWidth: 100,
      visible: false,
      visibleSearch:true,
      header: {
        filter: {
          title: '',
          key: 'ownerText',
          placeholder: '请输入',
          input: {},
        },
      }
    }, {
      field: 'workNo',
      title: '人员工号',
      minWidth: 120,
      header: {
        filter: {
          key: 'workNo',
          title: '人员工号',
          input: {},
          placeholder: '请输入人员工号'
        }
      }
    },
    {
      field: 'name',
      title: '人员姓名',
      minWidth: 100,
      header: {
        filter: {
          key: 'name',
          title: '人员姓名',
          input: {},
          placeholder: '请输入人员姓名'
        }
      }
    },
    {
      field: 'phone',
      title: '人员手机号',
      minWidth: 130,
      header: {
        filter: {
          key: 'phone',
          title: '人员手机号',
          input: {},
          placeholder: '请输入人员手机号'
        }
      }
    },
    {
      field: 'dtOrgInfo',
      title: '所属业务组织',
      minWidth: 180,
    },
    {
      field: 'jyOrgInfo',
      title: '所属嘉扬组织',
      minWidth: 180,
    },
    {
      field: 'jyCompile',
      title: '编制类型',
      width: 100,
      cell: {
        value: (row) => {
          return row.jyCompile ? '案场编制' : '非案场编制'
        },
        text: {}
      },
      header: {
        filter: {
          title: '编制类型',
          key: 'jyCompile',
          placeholder: '请选择',
          select: {
            options: [{
              key: '1',
              value: '案场编制'
            }, {
              key: '0',
              value: '非案场编制'
            }]
          }
        }
      }
    },
    {
      field: 'dtBuildingName',
      title: '编制所属案场',
      minWidth: 180,
    },
    {
      field: 'rankName',
      title: '当前职级',
      minWidth: 180,
    },
    {
      field: 'role',
      minWidth: 180,
      header: {
        filter: rolesOpt.create({
          key: 'roleIds',
          title: '人员角色',
          multiple: true,
          maxTagCount: 2
        })
      }
    },
    {
      field: 'status',
      title: '职位状态',
      width: 100,
      cell: {
        value: (row) => {
          return dt.dictInfo().__value('userStatus', row.status)
        },
        text: {}
      },
      header: {
        filter: {
          title: '职位状态',
          key: 'status',
          placeholder: '请选择',
          select: {
            options: userStatus()
          }
        }
      }
    },
    {
      field: 'validate',
      title: '人员状态',
      width: 100,
      slots: {
        default: (params, h) => {
          return [h('div', params.row.validate == 1 ? '启用' : '禁用')]
        }
      },
      header: {
        filter: {
          title: '人员状态',
          key: 'validate',
          placeholder: '请选择',
          select: {
            options: validateList()
          }
        }
      }
    },
    {
      field: 'handles',
      title: '操作',
      width: 170,
      fixed: 'right',
      cell: (item) => {
        let btn = []
        btn.push({
          title: '变更记录',
          event: 'onChenckLog',
        })
        btn.push({
          title: '编辑',
          code: '0201020000',
          event: 'onEdit',
        })
        if (item.validate == 1) {
          btn.push({
            title: '禁用',
            event: 'openAuthority',
            code: '0201040000',
            color: '#FF0000'
          })
        } else {
          btn.push({
            title: '启用',
            event: 'openAuthority',
            code: '0201040000',
            color: '#19BE6B'
          })
        }
        return {
          btn
        }
      }
    }]
  }

}

export default Column